package binance

import (
	"context"
	"encoding/json"
)

type ListTradeFeeService struct {
	c 			*Client
	symbol	 	string
}

type TradeFee struct {
	Symbol		string 		`json:"symbol"`
	MakerCommission	string 	`json:"makerCommission"`
	TakerCommission string 	`json:"takerCommission"`
}

func (s *ListTradeFeeService) Symbol (symbol string) *ListTradeFeeService {
	s.symbol = symbol
	return s
}

func (s *ListTradeFeeService) Do(ctx context.Context, opts ...RequestOption) (res []*TradeFee, err error) {
	r := &request{
		method:   "GET",
		endpoint: "/sapi/v1/asset/tradeFee",
		secType:  secTypeSigned,
	}
	if s.symbol != "" {
		r.setParam("symbol", s.symbol)
	}
	data, err := s.c.callAPI(ctx, r, opts...)
	if err != nil {
		return []*TradeFee{}, err
	}
	res = make([]*TradeFee, 0)
	err = json.Unmarshal(data, &res)
	if err != nil {
		return []*TradeFee{}, err
	}
	return res, nil
}

type ListInterestRateHistory struct {
	c 				*Client
	asset 			string
	vipLevel		*string
	startTime		*int64
	endTime			*int64
	limit 			*int
}
type InterestRateRecord struct {
	Asset 			string 		`json:"asset"`
	DailyInterestRate 	string 		`json:"dailyInterestRate"`
	Timestamp 		int64 		`json:"timestamp"`
	VipLevel		int 		`json:"vipLevel"`
}
func (s *ListInterestRateHistory) Asset(asset string) *ListInterestRateHistory {
	s.asset = asset
	return s
}
func (s *ListInterestRateHistory) VipLevel(vipLevel string) *ListInterestRateHistory {
	s.vipLevel = &vipLevel
	return s
}
func (s *ListInterestRateHistory) StartTime(startTime int64) *ListInterestRateHistory {
	s.startTime = &startTime
	return s
}
func (s *ListInterestRateHistory) EndTime(endTime int64) *ListInterestRateHistory {
	s.endTime = &endTime
	return s
}
func (s *ListInterestRateHistory) Limit(limit int) *ListInterestRateHistory {
	s.limit = &limit
	return s
}
func (s *ListInterestRateHistory) Do(ctx context.Context, opts ...RequestOption) (res []*InterestRateRecord, err error) {
	r := &request{
		method:   "GET",
		endpoint: "/sapi/v1/margin/interestRateHistory",
		secType:  secTypeSigned,
	}
	r.setParam("asset", s.asset)
	if s.vipLevel != nil {
		r.setParam("vipLevel", *s.vipLevel)
	}
	if s.startTime != nil {
		r.setParam("startTime", *s.startTime)
	}
	if s.endTime != nil {
		r.setParam("endTime", *s.endTime)
	}
	if s.limit != nil {
		r.setParam("limit", *s.limit)
	}

	data, err := s.c.callAPI(ctx, r, opts...)
	if err != nil {
		return []*InterestRateRecord{}, err
	}
	res = make([]*InterestRateRecord, 0)
	println(string(data))
	err = json.Unmarshal(data, &res)
	if err != nil {
		return []*InterestRateRecord{}, err
	}
	return res, nil
}
